VBScript 1.1.0
This example demonstrates how to make use of Persistent Variables in an ASP (Active Server Page) web page.
You will find it in the download package in the following folder
- \examples\External\asp
This little web page is meant to be used within a WebExtension in a SwyxIt! skin.
It displays the current status of the installed Night Switch example (see chapters A.1 and A2).
By clicking into the web page the status of the night switch will be toggled. The page also refreshes itself every 2 seconds, so if the night switch is getting switched from somewhere else, this page will also automatically shows the new status.
Default.asp
<meta http-equiv="refresh" content="2;url=<%=Request.ServerVariables("SCRIPT_NAME")%>">
<style>
body.on { background: #FFFF00; }
body.off { background: #C0C0C0; }
a { padding: 48% 50%; }
</style>
<!-- #include file = "PersistentVariables.inc"-->
<%
' configure the complete db connect string
g_sPersistentVariableConnectString = _
"Provider=sqloledb;" & _
"Data Source=WS-WELLIGE04;" & _
"Initial Catalog=" & PERSISTENT_VARIABLE_DATABASE & ";" & _
"User Id=PersistentVariables;" & _
"Password=PersistentVariables"
' initialize persistent variable
Dim NightSwitch
Set NightSwitch = new PersistentVariable
NightSwitch.Name = "NightSwitch"
NightSwitch.Default = 0
' evaluate url parameter
sUrlSwitch = Request.QueryString("switch")
if (sUrlSwitch <> "") and IsNumeric(sUrlSwitch) then NightSwitch.Value = CInt(sUrlSwitch)
' set display styles
if NightSwitch.Value = 0 then
sStyle = "off"
sSwitch = "1"
else
sStyle = "on"
sSwitch = "0"
end if
Set NightSwitch = Nothing
sURL = Request.ServerVariables("SCRIPT_NAME") & "?switch=" & sSwitch
%>
<body class="<%=sStyle%>">
<a href="<%=sURL%>"> </a>
</body>
You have to make sure, that the PersistenVariables.inc file is in the same folder as the default.asp file.
Please find a complete explanation of the usage of persistent variables outside of call routing scripts here:
By Tom Wellige
